/*#####################################*/
// Project Name : JSmartKit
// Author : Mr.Surachai Yindeeram
// Office : BrainStream Co.,Ltd.
// Create Date : Jan 29, 2013 5:42:06 PM
// Description : AES.java
/*#####################################*/
package com.xpaac.security;

import java.security.spec.AlgorithmParameterSpec;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import com.expaac.exception.LogException;

public class AES {
	private String algorithmInstance = "AES/CBC/PKCS5Padding";
	private String password = "";
	private String ivParam = "";
	public AES(String algorithmInstance) {
		this.algorithmInstance = algorithmInstance;
	}
	
	public AES() {
		
	}
	
	public byte[] encrypt(String plainText){
		try {
			byte[] input = plainText.getBytes();
		    byte[] keyBytes =password.getBytes();
		    SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
		    byte[] IV = new byte[16];
		    System.arraycopy(keyBytes, 0, IV, 0, 16);
		    AlgorithmParameterSpec IVspec = new IvParameterSpec("EmoMobile2013Key".getBytes());
		    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
		    cipher.init(Cipher.ENCRYPT_MODE, key,IVspec);
			return cipher.doFinal(input);
		} catch (Exception e) {
			try {
				throw new LogException(e);
			} catch (LogException e1) {
				// TODO Auto-generated catch block
				
			}
			return null;
		}
		
	}

	public String getAlgorithmInstance() {
		return algorithmInstance;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getIvParam() {
		return ivParam;
	}

	public void setIvParam(String ivParam) {
		this.ivParam = ivParam;
	}
	
	
	
	
	
	
	
}
